package com.zhongchaowuye.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.Page;
import com.zhongchaowuye.pojo.A_GYSh;
import com.zhongchaowuye.service.A_GYShService;

@Controller
@RequestMapping("/a_GYSh")
public class A_GYShController {

	@Resource
	private A_GYShService a_GYShService;
	
	@RequestMapping(value ="/getA_GYSh",method = RequestMethod.POST)
	@ResponseBody
	//根据id获取A_GYSh对象信息
	public Map<String,Object> getA_GYSh(HttpServletRequest request,A_GYSh gysh){
		Map<String,Object> m=new HashMap<>();
		Map<String,Object> reMap=new HashMap<>();
		try {
			A_GYSh a_GYSh=a_GYShService.getA_GYSh(gysh);
			reMap.put("a_GYSh", a_GYSh);
			reMap.put("status", "success");
			reMap.put("message", "OK");
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			reMap.put("status", "error");
			reMap.put("message", "ERROR："+e.getMessage());
		}
		return reMap;
	}

	@RequestMapping(value ="/getA_GYShList",method = RequestMethod.POST)
	@ResponseBody
	//获取列表
	public Map<String,Object> getA_GYShList(HttpServletRequest request,A_GYSh a_GYSh){
		Map<String,Object> reMap=new HashMap<>();//定义返回值，其中有一项必须是集合，先按照下面的写法
		try {
			List<Map<String,Object>> rList=a_GYShService.getA_GYShList(a_GYSh); //不带分页（注意实现类中的相应写法）
			//Page<Map<String,Object>> rList = (Page)a_GYShService.getA_GYShList(a_GYSh);
			
			//System.out.println(rList);
			reMap.put("rows", rList);
			//reMap.put("total", rList.getTotal());
			//reMap.put("pageIndex", a_GYSh.getPageIndex());
			//reMap.put("pageSize", a_GYSh.getPageSize());
			reMap.put("status", "success");
			reMap.put("message", "OK");
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			reMap.put("status", "error");
			reMap.put("message", "ERROR");
		}
		return reMap;
	}

	@RequestMapping(value ="/getA_GYShList_quchongming",method = RequestMethod.POST)
	@ResponseBody
	//获取去重后的供应商名字列表
	public Map<String,Object> getA_GYShList_quchongming(HttpServletRequest request,A_GYSh a_GYSh){
		Map<String,Object> reMap=new HashMap<>();//定义返回值，其中有一项必须是集合，先按照下面的写法
		try {
			List<Map<String,Object>> rList=a_GYShService.getA_GYShList_quchongming(a_GYSh); //不带分页（注意实现类中的相应写法）
			//Page<Map<String,Object>> rList = (Page)a_GYShService.getA_GYShList(a_GYSh);
			for(Map m:rList){ 
				m.put("children", null); //为前端属性可多选控件补充一个必须的属性
			}
			//System.out.println(rList);
			reMap.put("rows", rList);
			//reMap.put("total", rList.getTotal());
			//reMap.put("pageIndex", a_GYSh.getPageIndex());
			//reMap.put("pageSize", a_GYSh.getPageSize());
			reMap.put("status", "success");
			reMap.put("message", "OK");
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			reMap.put("status", "error");
			reMap.put("message", "ERROR");
		}
		return reMap;
	}

	@RequestMapping(value ="/getPhoneList",method = RequestMethod.POST)
	@ResponseBody
	//获取列表
	public Map<String,Object> getPhoneList(HttpServletRequest request,A_GYSh a_GYSh){
		Map<String,Object> reMap=new HashMap<>();//定义返回值，其中有一项必须是集合，先按照下面的写法
		try {
			List<Map<String,Object>> rList=a_GYShService.getPhoneList(a_GYSh); //不带分页（注意实现类中的相应写法）
			//Page<Map<String,Object>> rList = (Page)a_GYShService.getPhoneList(a_GYSh);
			for(Map m:rList){
				String lxr=(String)m.get("gyshang_lianxiren");//取得联系人
				String phone=(String)m.get("gyshang_phone");//取得联系电话
				m.put("lxr_phone", lxr+":"+phone);//在每行记录中补充1个用于显示的值
			}
			//System.out.println(rList);
			reMap.put("rows", rList);
			reMap.put("total", rList.size());
			reMap.put("status", "success");
			reMap.put("message", "OK");
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			reMap.put("status", "error");
			reMap.put("message", "ERROR");
		}
		return reMap;
	}
	
	@RequestMapping(value ="/insertA_GYSh",method = RequestMethod.POST)
	@ResponseBody
	//添加
	public Map<String,Object> insertA_GYSh(HttpServletRequest request,A_GYSh a_GYSh)   
	{
		Map<String,Object> reMap=new HashMap<>();//返回值map
		try 
		{
			int flag=a_GYShService.insertA_GYSh(a_GYSh);
			//int flag = 0;
			if(flag>0)
			{
				reMap.put("status", "success");
				reMap.put("message", "OK");
			}
			else
			{
				reMap.put("status", "error");
				reMap.put("message", "ERROR");
			}
			
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			reMap.put("status", "error");
		}
		return reMap;
	}
	
	@RequestMapping(value ="/updateA_GYSh",method = RequestMethod.POST)
	@ResponseBody
	//修改
	public Map<String,Object> updateA_GYSh(HttpServletRequest request,A_GYSh a_GYSh)   
	{
		Map<String,Object> reMap=new HashMap<>();//返回值map
		try 
		{
			int flag=a_GYShService.updateA_GYSh(a_GYSh);
			if(flag>0)
			{
				reMap.put("status", "success");
				reMap.put("message", "OK");
			}
			else
			{
				reMap.put("status", "error");
				reMap.put("message", "ERROR");
			}
			
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			reMap.put("status", "error");
		}
		return reMap;
	}
	
	@RequestMapping(value ="/delA_GYSh",method = RequestMethod.POST)
	@ResponseBody
	//软删除
	public Map<String,Object> delA_GYSh(HttpServletRequest request,A_GYSh a_GYSh)   
	{
		Map<String,Object> reMap=new HashMap<>();//返回值map
		Map<String,Object> m=new HashMap<>();
		try 
		{
			int flag=a_GYShService.delA_GYSh(a_GYSh);
			if(flag>0)
			{
				reMap.put("status", "success");
				reMap.put("message", "OK");
			}
			else
			{
				reMap.put("status", "error");
				reMap.put("message", "ERROR");
			}
			
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			reMap.put("status", "error");
		}
		return reMap;
	}
}
